/**
 * Title: jFamilyTree SQL provider
 * Description: jFamilyTree SQL provider
 * About: Designed and rewritten by Andreas Lundgren, based on the Treebolic application suite
 * Copyright: (c) 2001-2008
 * Terms of use:see license agreement at http://treebolic.sourceforge.net/en/license.htm
 * Author: Bernard Bou
 * Company: bsys
 */
package jFamilyTree.provider.sql;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;

/**
 * SQL properties
 * 
 * @author Bernard Bou
 */
public class SqlProperties
{
	/**
	 * Load properties
	 */
	static public Properties load(URL thisUrl)
	{
		try
		{
			Properties theseProperties = new Properties();
			InputStream thisInputStream = thisUrl.openStream();
			theseProperties.load(thisInputStream);
			return theseProperties;
		}
		catch (IOException e)
		{
			System.err.println("Sql: Cannot load <" + thisUrl.toString() + ">");
			return null;
		}
	}

	/**
	 * Save properties
	 */
	static void save(Properties theseProperties, String thisPropertyFile)
	{
		try
		{
			theseProperties.store(new FileOutputStream(thisPropertyFile), "TREEBOLIC-SQL");
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	/**
	 * Make default property
	 */
	static public String toString(Properties theseProperties)
	{
		StringBuffer thisBuffer = new StringBuffer();
		for (Enumeration<?> thisEnum = theseProperties.propertyNames(); thisEnum.hasMoreElements();)
		{
			String thisName = (String) thisEnum.nextElement();
			String thisValue = theseProperties.getProperty(thisName);
			thisBuffer.append(thisName);
			thisBuffer.append("=");
			thisBuffer.append(thisValue);
			thisBuffer.append("\n");
		}
		return thisBuffer.toString();
	}
}
